package com.kmzx.one.project.net;

import com.kmzx.one.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.CollectionUtils;

import java.util.List;

@ApiModel(description = "下订单的参数列表")
public class OrderParam {

    @ApiModelProperty(value = "购物车下单")
    public CartParam cart;

    @ApiModelProperty(value = "立即购买下单")
    public OnceParam once;

    public CartParam getCart() {
        return cart;
    }

    public OrderParam setCart(CartParam cart) {
        this.cart = cart;
        return this;
    }

    public OnceParam getOnce() {
        return once;
    }

    public OrderParam setOnce(OnceParam once) {
        this.once = once;
        return this;
    }


    public int checkWhich() {
        CartParam cart = this.getCart();

        if (cart != null) {
            String userId = cart.getUserId();
            List<String> ids = cart.getIds();
            if (StringUtils.isNotEmpty(userId) && !CollectionUtils.isEmpty(ids)) {
                return 1;
            }
        }


        OnceParam once = this.getOnce();

        if (once != null) {
            String oneUser = once.getUserId();
            String skuId = once.getSkuId();
            if (StringUtils.isNotEmpty(oneUser) && StringUtils.isNotEmpty(skuId)) {
                return 2;
            }
        }
        return 0;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("OrderParam{");
        sb.append("cart=").append(cart);
        sb.append(", once=").append(once);
        sb.append('}');
        return sb.toString();
    }
}
